//
//  CMDBRegisterBirthTF.swift
//  CMDB
//
//  Created by 王磊 on 08/05/2017.
//  Copyright © 2017 CMDB. All rights reserved.
//

import UIKit

class CMDBRegisterClickTF: CMDBRegisterTF {
    
    internal var background: UIButton = UIButton(type: .Custom)
    
    internal var detailLabel: UILabel = UILabel()
    
    internal var btn: UIButton = UIButton(type: .Custom)
    
}
extension CMDBRegisterClickTF {
    
}
extension CMDBRegisterClickTF {
    
    override func addOwnSubviews() {
        super.addOwnSubviews()
        
        addSubview(background)
        
        addSubview(detailLabel)
        
        addSubview(btn)
    }
    override func configOwnSubviews() {
        super.configOwnSubviews()
        
        sendSubviewToBack(background)
        
        background.addTarget(self, action: #selector(btnClick), forControlEvents: .TouchUpInside)
        
        btn.setImage(UIImage(named: "user_reg_birth"), forState: .Normal)
    }
    
}

extension CMDBRegisterClickTF {
    
    @objc private func btnClick() {
        
        if let target = unsureTarget {
            
            let argu = ArguInfo()
            
            argu.view = self
            //
            argu.controlEvent = .ItemClick
            
            TSRuntimeManager.getInstance().addTarget(target, andSel: unsureAction!, andAnyArgu: argu)
        }
    }
}

extension CMDBRegisterClickTF {
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        detailLabel.snp_makeConstraints { [weak self] (make) in
            
            make.left.equalTo(self!.textWidth)
            
            make.centerY.equalTo(5)
        }
        
        let image = UIImage(named: "user_reg_birth")
        
        btn.snp_makeConstraints { (make) in
            
            make.right.equalTo(-5)
            
            make.centerY.equalTo(5)
            
            make.width.equalTo(image!.size.width)
            
            make.height.equalTo(image!.size.height)
        }
        
        background.frame = bounds
    }
}